<template>
  <!-- 问题二级分类表单弹窗 -->
  <el-dialog
    :close-on-click-modal="false"
    v-model="visibleDialog"
    :title="props.title"
    :width="!props.isReadonly ? '1400px' : '1000px'"
    draggable
    @close="closeDialog"
  >
    <el-row :gutter="20">
      <!-- 目录树 -->
      <el-col :lg="4" :md="5" :sm="6" :xs="24" class="mb-[12px] !pr-0">
        <div
          style="
            display: flex;
            justify-content: space-between;
            align-items: center;
          "
        >
          <div class="mb-[10px] text-[13px]" style="font-weight: 700">
            巡检路线
          </div>
        </div>
        <el-tree
          style="max-width: 600px"
          node-key="id"
          ref="treeRef"
          :data="formData.routeLocationList"
          :props="defaultProps"
          :highlight-current="true"
          :default-expanded-keys="['quanbu']"
          @node-click="handleNodeClick"
        />
      </el-col>
      <el-col :lg="20" :md="19" :sm="18" :xs="24">
        <div
          style="
            display: flex;
            justify-content: space-between;
            align-items: center;
          "
        >
          <div class="mb-[10px] text-[13px]" style="font-weight: 700">
            巡检信息
          </div>
        </div>
        <el-form ref="formRef" :model="formData" label-width="100">
          <el-row>
            <el-col :span="8">
              <el-form-item
                label="巡检任务"
                prop="taskName"
                style="display: flex"
              >
                <el-input
                  style="width: 200px"
                  v-if="!props.isReadonly"
                  v-model="formData.taskName"
                  placeholder="请输入巡检任务"
                  clearable
                  disabled
                />
                <span
                  @click="openDialogdetail()"
                  style="
                    color: #0a1dba;
                    text-decoration: underline;
                    margin-left: 10px;
                    cursor: pointer;
                  "
                  >查看计划</span
                >
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="任务编号" prop="taskNo">
                <el-input
                  v-if="!props.isReadonly"
                  v-model="formData.taskNo"
                  placeholder="请输入任务编号"
                  clearable
                  disabled
                />
              </el-form-item>
            </el-col>
            <el-form-item label="巡检类型">
              <el-select
                v-model="formData.sopTypeId"
                placeholder="请选择巡检类型"
                clearable
                disabled
                style="width: 275px"
              >
                <el-option
                  v-for="item in sopTypeList"
                  :key="item.id"
                  :label="item.sopTypeName"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>

            <el-col :span="8">
              <el-form-item label="巡检状态" prop="taskStatus">
                <el-select
                  v-model="formData.taskStatus"
                  placeholder="请选择巡检状态"
                  clearable
                  disabled
                  style="width: 280px"
                >
                  <el-option
                    v-for="item in useDictionary('EamInspectTaskStatus')"
                    :key="item.value"
                    :label="item.label"
                    :value="Number(item.value)"
                  />
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="计划巡检日期" prop="planExecuteTime">
                <el-date-picker
                  style="width: 280px"
                  v-if="!props.isReadonly"
                  v-model="formData.planExecuteTime"
                  type="date"
                  placeholder="请选择计划巡检日期"
                  format="YYYY/MM/DD"
                  value-format="YYYY-MM-DD"
                  disabled
                />
                <!-- <el-input
                  v-if="!props.isReadonly"
                  v-model="formData.planExecuteTime"
                  placeholder="请输入计划巡检日期"
                  clearable
                /> -->
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="巡检开始时间" prop="startExecuteTime">
                <el-date-picker
                  style="width: 280px"
                  v-if="!props.isReadonly"
                  v-model="formData.startExecuteTime"
                  type="date"
                  placeholder="请选择计划巡检日期"
                  format="YYYY-MM-DD HH:mm:ss"
                  value-format="YYYY-MM-DD HH:mm:ss"
                  disabled
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="巡检结束时间" prop="endExecuteTime">
                <el-date-picker
                  style="width: 280px"
                  v-if="!props.isReadonly"
                  v-model="formData.endExecuteTime"
                  type="date"
                  placeholder="请选择计划巡检日期"
                  format="YYYY-MM-DD HH:mm:ss"
                  value-format="YYYY-MM-DD HH:mm:ss"
                  disabled
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="巡检班组" prop="executeTeamName">
                <el-input
                  v-if="!props.isReadonly"
                  v-model="formData.executeTeamName"
                  placeholder="请输入巡检班组"
                  clearable
                  disabled
                />
              </el-form-item>
            </el-col>
            <!-- <el-col :span="8">
              <el-form-item label="巡检负责人" prop="executePersonName">
                <el-input
                  v-if="!props.isReadonly"
                  v-model="formData.executePersonName"
                  placeholder="请输入巡检负责人"
                  clearable
                  disabled
                />
              </el-form-item>
            </el-col> -->
          </el-row>
        </el-form>
        <div
          style="
            display: flex;
            justify-content: space-between;
            align-items: center;
          "
        >
          <div
            class="mb-[10px] text-[13px]"
            style="font-weight: 700; display: flex"
          >
            设备列表
            <div style="font-size: 12px; font-weight: 400; color: red">
              (注：点击列表行显示相应巡检项)
            </div>
          </div>
        </div>
        <div class="formTable">
          <el-table
            :data="tableData"
            max-height="200px"
            :key="Math.random"
            highlight-current-row
            border
            @current-change="handleEquSelectionChange"
            show-overflow-tooltip
          >
            <el-table-column
              label="状态"
              prop="orderStatus"
              min-width="100"
              show-overflow-tooltip
              align="center"
            >
              <template #default="scope">
                <el-tag v-show="scope.row.orderStatus !== 0">{{
                  useDictionary("InspectionStatus", scope.row.orderStatus ?? "")
                }}</el-tag>
                <el-tag v-show="scope.row.orderStatus == 0" type="success">{{
                  useDictionary("InspectionStatus", scope.row.orderStatus ?? "")
                }}</el-tag>
              </template>
            </el-table-column>

            <el-table-column
              label="设备编码"
              align="left"
              props="assetCode"
              min-width="150"
            >
              <template #default="{ $index, row }">
                <span>{{ row.assetCode }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="设备名称"
              props="assetName"
              min-width="150"
              align="left"
            >
              <template #default="{ $index, row }">
                <span>{{ row.assetName }}</span>
              </template>
            </el-table-column>

            <el-table-column
              label="设备位置"
              props="locationName"
              min-width="150"
              align="left"
            >
              <template #default="{ $index, row }">
                <span>{{ row.locationName }}</span>
              </template>
            </el-table-column>
            <!-- :rules="rules.sonsopStandardId" -->
            <el-table-column
              label="巡检项目进度"
              props="taskPersonIds"
              min-width="130"
              align="center"
            >
              <template #default="scope">
                <span style="color: #4251c9">
                  未检({{
                    scope.row.notInspectedNumber
                      ? scope.row.notInspectedNumber
                      : 0
                  }})</span
                >
                <span style="color: #c8554a">
                  异常({{
                    scope.row.exceptionNumber ? scope.row.exceptionNumber : 0
                  }})</span
                >
              </template>
            </el-table-column>
            <!-- <el-table-column
              label="巡检开始时间"
              props="startExecuteTime"
              min-width="220"
              align="center"
              style="padding-top: 15px"
            >
              <template #default="{ $index, row }">
                <span>{{ row.startExecuteTime }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="巡检结束时间"
              props="endExecuteTime"
              min-width="220"
              align="center"
              style="padding-top: 15px"
            >
              <template #default="{ $index, row }">
                <span>{{ row.endExecuteTime }}</span>
              </template>
            </el-table-column> -->
            <el-table-column
              label="巡检时间"
              props="workTime"
              min-width="220"
              align="center"
              style="padding-top: 15px"
            >
              <template #default="{ $index, row }">
                <span>{{ row.workTime }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="巡检标准"
              props="sopStandardCode"
              min-width="220"
              align="center"
              style="padding-top: 15px"
            >
              <template #default="{ $index, row }">
                <span>{{ "" }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="巡检人员"
              props="executePersonName"
              min-width="130"
              align="center"
            >
              <template #default="{ $index, row }">
                <span>{{ row.executePersonName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="问题说明" min-width="150">
              <template #default="{ $index, row }">
                <span>{{ row.problemDesc }}</span>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination
            small
            :background="true"
            :current-page="pageable.pageNum"
            :page-size="pageable.pageSize"
            :page-sizes="[5, 10, 20, 50]"
            :total="pageable.total"
            layout="total, sizes, prev, pager, next, jumper"
            class="mt-[10px]"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
        <div
          style="
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-top: 20px;
          "
        >
          <el-radio-group v-model="hh" @change="handleRadioChange">
            <el-radio-button label="全部巡检项" value="2" />
            <el-radio-button label="异常巡检项" value="0" />
          </el-radio-group>
        </div>
        <div class="formTable">
          <el-table
            :data="paginatedData"
            style="width: 100%"
            max-height="200px"
            :key="Math.random"
            border
            show-overflow-tooltip
          >
            <el-table-column
              label="巡检项"
              props="sopItemName"
              min-width="150"
              align="left"
            >
              <template #default="{ $index, row }">
                <span>{{ row.sopItemName }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="巡检方法"
              props="assetName"
              min-width="150"
              align="left"
            >
              <template #default="{ $index, row }">
                <span>{{ row.sopItem.sopItemMethod }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="巡检工具"
              props="assetTypeName"
              min-width="140"
              align="left"
            >
              <template #default="{ $index, row }">
                <span>{{ row.sopItem.sopItemTool }}</span>
              </template>
            </el-table-column>

            <el-table-column
              label="巡检记录"
              props="sopItemValue"
              min-width="90"
            >
              <template #default="{ $index, row }">
                <span>{{ row.sopItemValue }}</span>
              </template>
            </el-table-column>
            <!-- :rules="rules.sonsopStandardId" -->
            <el-table-column
              label="巡检结果"
              props="sopItemResult"
              min-width="80"
              align="center"
            >
              <template #default="{ $index, row }">
                {{
                  row.sopItemResult === "1"
                    ? "正常"
                    : row.sopItemResult === "0"
                    ? "异常"
                    : ""
                }}
              </template>
            </el-table-column>
            <el-table-column
              label="标准值"
              props="taskPersonIds"
              min-width="100"
              align="center"
            >
              <template #default="{ $index, row }">
                {{ row.sopItem.standardMinValue }} -
                {{ row.sopItem.standardMaxValue }}
              </template>
            </el-table-column>

            <el-table-column
              label="图片"
              props="image"
              min-width="100"
              align="center"
            >
              <template #default="{ $index, row }">
                <div style="overflow-x: auto">
                  <span v-for="(item, index) in row.images" :key="index">
                    <img
                      :src="`${upPreviewUrl}${item.url}`"
                      style="
                        width: 30px;
                        height: 30px;
                        margin-right: 10px;
                        cursor: pointer;
                      "
                      @click="
                        handlePictureCardPreview(`${upPreviewUrl}${item.url}`)
                      "
                      alt=""
                    />
                  </span>
                </div>
              </template>
            </el-table-column>
          </el-table>

          <el-pagination
            small
            :background="true"
            :current-page="currentPage"
            :page-size="pageSize"
            :page-sizes="[5, 10, 20, 50]"
            :total="inspectionList.length"
            layout="total, sizes, prev, pager, next, jumper"
            class="mt-[20px]"
            @size-change="handleEquSizeChange"
            @current-change="handleEquCurrentChange"
          />
        </div>
      </el-col>
    </el-row>

    <template #footer>
      <div class="dialog-footer">
        <!-- <el-button
          v-if="!props.isReadonly"
          type="primary"
          :loading="loading"
          @click="handleSubmit"
          >确 定</el-button
        > -->
        <el-button @click="closeDialog">取 消</el-button>
      </div>
    </template>
    <eaminspectionplan-edit
      :visible="addDialog.visible"
      :title="addDialog.title"
      :data="addDialog.data"
      :is-readonly="addDialog.readvisible"
      @change-visible="changeVisible1"
    />
  </el-dialog>
</template>

<script setup lang="ts">
import request from "@/utils/request";
import { useDictStoreHook } from "@/store/modules/dictionary"; // 引入
import { useRouter } from "vue-router";
const dictionaryStore = useDictStoreHook();
import { useTable, useDownload, useDictionary } from "@/utils/useTable";
const router = useRouter();

defineOptions({
  name: "EAMEQUROUTEINSPECTIONTASKEDIT",
  inheritAttrs: false,
});
const defaultProps = {
  children: "children",
  label: "locationName",
};
const handleNodeClick = (data: Tree) => {
  hh.value = "全部巡检项";
  if (data.id == "quanbu") {
    searchParam.value.inspectionTaskId = formData.id;
    searchParam.value.locationId = "";
    inspectionList.value = [];
    getTableList();
  } else {
    console.log(data);

    inspectionList.value = [];
    searchParam.value.inspectionTaskId = formData.id;
    searchParam.value.locationId = data.locationId;
    getTableList();
  }
};

const hh = ref("全部巡检项");

const handleRadioChange = (e) => {
  console.log(e);
  if (e == "全部巡检项") {
    currentPage.value = 1;
    pageSize.value = 5;
    inspectionList.value = oldInspectionList.value;
  } else if (e == "异常巡检项") {
    console.log("异常巡检项", inspectionList.value);

    currentPage.value = 1;
    pageSize.value = 5;
    inspectionList.value = inspectionList.value.filter((item) => {
      return item.sopItemResult == "0";
    });
  }
};

const uploadApi = import.meta.env.VITE_APP_BASE_API;
// 预览url前缀
const upPreviewUrl = `${uploadApi}/system/fileCenter/preview/`;

const handlePictureCardPreview = (url: string) => {
  url = url?.replace("fileCenter/download/", "fileCenter/preview/");
  window.open(url);
};

// 前端分页
const currentPage = ref(1);
const pageSize = ref(5);

const paginatedData = computed(() => {
  const start = (currentPage.value - 1) * pageSize.value;
  const end = start + pageSize.value;
  return inspectionList.value.slice(start, end);
});
const handleEquSizeChange = (newSize: number) => {
  pageSize.value = newSize;
};
const handleEquCurrentChange = (newPage: number) => {
  currentPage.value = newPage;
};

// 请求参数
const requestApi = "/eam/equRouteInspectionOrder/queryByTask";

// 是否需要分页
const pagination = true;

const initParam = {};

// 初始化搜索参数数据
const searchParamInit = {
  inspectionTaskId: "",
  locationId: "",
};

const deleteParam = {
  api: "/qms/qmsexceptionsubtype/delete",
  data: {},
};

// 数据请求错误后处理
function requestError() {}

const dataCallBack = ref(undefined); // 无需二次数据处理&不传赞数也行

// 表格操作 Hooks
const {
  tableData,
  pageable,
  searchParam,
  ids,
  getTableList,
  search,
  reset,
  handleSizeChange,
  handleCurrentChange,
  handleSelectionChange,
  handleTableDelete,
  loading,
}: any = useTable(
  requestApi,
  initParam,
  searchParamInit,
  pagination,
  dataCallBack.value,
  requestError,
  deleteParam
);

// // 请求参数
// const equRequestApi = "/eam/equInspectionTask/queryByPage";

// // 是否需要分页
// const equPagination = true;

// const equInitParam = {};

// // 初始化搜索参数数据
// const equSearchParamInit = {
//   inspectionPlanld: "",
//   executeTeamld: "",
//   taskNo: "",
//   taskStatus: "",
//   inspectionStartDate: "",
//   inspectionEndDate: "",
//   inspectionDateSearch: [],
// };

// const equDeleteParam = {
//   api: "/qms/qmsexceptionsubtype/delete",
//   data: {},
// };

// // 数据请求错误后处理
// function equRequestError() {}

// const equDataCallBack = ref(undefined); // 无需二次数据处理&不传赞数也行

// let equTable = useTable(
//   equRequestApi,
//   equInitParam,
//   equSearchParamInit,
//   equPagination,
//   equDataCallBack.value,
//   equRequestError,
//   equDeleteParam
// );

const emit = defineEmits(["reset-table", "change-visible"]);

const props = defineProps({
  visible: {
    type: Boolean,
    default: () => {
      return false;
    },
  },
  title: {
    type: String,
    default: () => {
      return "";
    },
  },
  data: {
    type: Object,
    default: () => {
      return {};
    },
  },
  isReadonly: {
    type: Boolean,
    default: () => {
      return false;
    },
  },
});

const visibleDialog = ref(false);
const treeRef = ref();
watch(
  () => props.visible,
  (newVal: boolean) => {
    visibleDialog.value = newVal;

    setTimeout(() => {
      formRef.value.clearValidate();
      console.log(tableData.value);
    }, 50);
  }
);

const rules = reactive({
  exceptionTypeCode: [
    { required: true, message: "请选择分类问题", trigger: "change" },
  ],

  exceptionTypeSubCode: [
    { required: true, message: "请输入二级分类编号", trigger: "blur" },
    { min: 1, max: 50, message: "长度在 1 到 50 个字符", trigger: "blur" },
  ],
  exceptionTypeSubName: [
    { required: true, message: "请输入二级分类名称", trigger: "blur" },
    { min: 1, max: 50, message: "长度在 1 到 50 个字符", trigger: "blur" },
  ],
  version: [],
  remarks: [
    { min: 1, max: 255, message: "长度在 1 到 255 个字符", trigger: "blur" },
  ],
  enabled: [],
});

const formRef = ref(ElForm);

let formData = reactive({
  assetKind: "",
  createTime: "",
  createdUserId: "",
  createdUserName: "",
  endExecuteTime: "",
  exceptionNumber: "",
  executePersonId: "",
  executePersonName: "",
  executeTeamName: "",
  id: "",
  ids: "",
  inspectTotalNumber: "",
  inspectionPlanId: "",
  inspectionRouteId: "",
  inspectionRouteName: "",
  lastUpdateTime: "",
  lastUpdatedUserId: "1",
  lastUpdatedUserName: "",
  notInspectedNumber: "",
  organizationId: "",
  planExecuteTime: "",
  responseTime: "",
  routeLocationList: [],
  sopTypeId: "",
  startExecuteTime: "",
  taskName: "",
  taskNo: "",
  taskStatus: "",
  version: "",
});

watch(
  () => props.data,
  async (newVal: any) => {
    formData.id = "";
    if (newVal?.id) {
      const {
        assetKind,
        createTime,
        createdUserId,

        endExecuteTime,
        exceptionNumber,
        executePersonId,
        executePersonName,
        executeTeamName,
        id,
        ids,
        inspectTotalNumber,
        inspectionPlanId,
        inspectionRouteId,
        inspectionRouteName,
        lastUpdateTime,
        lastUpdatedUserId,
        lastUpdatedUserName,
        notInspectedNumber,
        organizationId,
        planExecuteTime,
        responseTime,
        routeLocationList,
        sopTypeId,
        startExecuteTime,
        taskName,
        taskNo,
        taskStatus,
        version,
      } = newVal;
      Object.assign(formData, {
        assetKind,
        createTime,
        createdUserId,

        endExecuteTime,
        exceptionNumber,
        executePersonId,
        executePersonName,
        executeTeamName,
        id,
        ids,
        inspectTotalNumber,
        inspectionPlanId,
        inspectionRouteId,
        inspectionRouteName,
        lastUpdateTime,
        lastUpdatedUserId,
        lastUpdatedUserName,
        notInspectedNumber,
        organizationId,
        planExecuteTime,
        responseTime,
        routeLocationList,
        sopTypeId,
        startExecuteTime,
        taskName,
        taskNo,
        taskStatus,
        version,
      });
      // 给路线添加全部
      formData.routeLocationList?.unshift({
        id: "quanbu",
        locationName: "全部",
      });
      searchParam.value.inspectionTaskId = formData.id;
      searchParam.value.locationId = "";
      // getTableList();
      await oneList();
      // 下一次更新选中路线全部
      nextTick(() => {
        treeRef.value.setCurrentKey(formData.routeLocationList[0]?.id, true);
      });
    }
  }
);

async function oneList() {
  await getTableList();
  getInspectionList(tableData.value[0].id, tableData.value[0].sopStandardId);
}

/** 关闭表单弹窗 */
function closeDialog() {
  visibleDialog.value = false;
  emit("change-visible", false);
  resetForm();
}

/** 重置表单 */
function resetForm() {
  formRef.value.resetFields();
  formRef.value.clearValidate();
  formData.assetKind = "";
  formData.createTime = "";
  formData.createdUserId = "";
  formData.createdUserName = "";
  formData.endExecuteTime = "";
  formData.exceptionNumber = "";
  formData.executePersonId = "";
  formData.executePersonName = "";
  formData.executeTeamName = "";
  formData.id = "";
  formData.ids = "";
  formData.inspectTotalNumber = "";
  formData.inspectionPlanId = "";
  formData.inspectionRouteId = "";
  formData.inspectionRouteName = "";
  formData.lastUpdateTime = "";
  formData.lastUpdatedUserId = "";
  formData.lastUpdatedUserName = "";
  formData.notInspectedNumber = "";
  formData.organizationId = "";
  formData.planExecuteTime = "";
  formData.responseTime = "";
  formData.routeLocationList = [];
  formData.sopTypeId = "";
  formData.startExecuteTime = "";
  formData.taskName = "";
  formData.taskNo = "";
  formData.taskStatus = "";
  formData.version = "";
  equList.value = [];
  inspectionList.value = [];
  oldInspectionList.value = [];
  hh.value = "全部巡检项";
}

// const loading = ref(false);

/** 问题二级分类保存提交 */
function handleSubmit() {
  formRef.value.validate(async (valid: any) => {
    if (valid) {
      loading.value = true;
      const text = formData.id ? "编辑" : "新增";
      await request({
        url: "/qms/qmsexceptionsubtype/save",
        method: "post",
        data: formData,
      }).finally(() => {
        loading.value = false;
      });
      ElMessage.success(text + `成功`);
      closeDialog();
      emit("reset-table", formData.id);
    }
  });
}

// 巡检类型
const sopTypeList = ref([]);
const getSopTypeList = async () => {
  await request({
    url: "/eam/eamsoptype/getList",
    method: "post",
    data: {},
  }).then((res) => {
    sopTypeList.value = res.data;
    console.log(" sopTypeList.value", sopTypeList.value);
  });
};

// 产看计划（跳转）
const handlePLanClick = () => {
  console.log("跳转");
  router.push({
    path: "/eam/equ/eaminspectionplan",
    query: {
      taskName: formData.taskName,
      sopTypeId: formData.sopTypeId,
    },
  });
};

// 获取设备列表
const equList = ref([]);
const getEquList = async (inspectionTaskId: "", locationId: "") => {
  await request({
    url: "/eam/equRouteinspectionOrder/queryMylist",
    method: "post",
    data: { inspectionTaskId: inspectionTaskId, locationId: locationId },
  }).then((res) => {
    equList.value = res.data;
    console.log(" equList.value", equList.value);
  });
};

// 选中设备列表
const handleEquSelectionChange = (e) => {
  hh.value = "全部巡检项";
  if (e) {
    getInspectionList(e.id, e.sopStandardId);
  }
};

//获取巡检列表
const oldInspectionList = ref([]);
const inspectionList = ref([]);
const getInspectionList = async (id, sopStandardId) => {
  await request({
    url: "/eam/eampointcheckorder/getDetails",
    method: "post",
    data: { id: id, sopStandardId: sopStandardId },
  }).then((res) => {
    inspectionList.value = res.data;
    oldInspectionList.value = res.data;
    console.log(" inspectionList.value", inspectionList.value);
  });
};

// 产看计划（跳转）
const addDialog = reactive<DialogOption>({
  visible: false,
  readvisible: false,
  title: "",
  data: {},
});
// 查询详情
async function getInfo(id: string) {
  request({
    url: `/eam/equRouteInspectionPlan/get/${id}`,
    method: "get",
  })
    .then((data) => {
      addDialog.data = data.data;
      addDialog.visible = true;
    })
    .catch((res) => {
      console.log(res);
    });
}

/** 打开巡检计划表单弹窗 */
function openDialog(roleObj?: Object) {
  if (roleObj) {
    addDialog.title = "修改巡检计划";
    getInfo(roleObj.id);
  } else {
    addDialog.title = "新增巡检计划";
    addDialog.visible = true;
  }
  addDialog.readvisible = false;
}

/** 打开巡检计划表单弹窗 详情 */
function openDialogdetail(roleObj?: any) {
  console.log("roleObj", formData.inspectionPlanId);
  addDialog.title = "巡检计划详情";
  getInfo(formData.inspectionPlanId);
  addDialog.readvisible = true;
}

function changeVisible1(value: boolean) {
  addDialog.visible = value;
  if (!value) {
    addDialog.data = {};
  }
}

onMounted(() => {
  getSopTypeList();
});
// 组件销毁时调用
onBeforeUnmount(() => {
  visibleDialog.value = false;
  emit("change-visible", false);
});
</script>
<style lang="scss" scoped>
:deep(.el-descriptions__label.el-descriptions__cell.is-bordered-label) {
  width: 120px;
}
:deep(.el-descriptions__content.el-descriptions__cell.is-bordered-content) {
  min-width: 120px;
}
</style>
